package com.coding.base.util;

import com.coding.pojo.Poem;
import com.coding.pojo.PoemBasic;

import java.util.ArrayList;
import java.util.List;

/**
 * @auther wangchenghao
 * @date 2020/8/3
 **/
public class PoemUtil {
    public static List<PoemBasic> setPoemText(List<PoemBasic> poemBasicList) {
        String regEx = "[\\s+\r\n`~!@#$%^&*()-_—+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。， 、？]";
        String regExless = "[\\s+\r\n。.?？]";
        for (PoemBasic poembasic : poemBasicList
        ) {
            String[] s = poembasic.getPoem().getPoem_text().split(regExless);
            List<String> newstrings = new ArrayList<>();
            for (int j = 0; j < s.length; j++) {
                if (!s[j].isEmpty()) {
                    newstrings.add(s[j]);
                }
            }
            poembasic.getPoem().setPoem_textlines(newstrings);
        }
        return poemBasicList;

    }

    public static PoemBasic setPoemText(PoemBasic poemBasic) {
        String regEx = "[\\s+\r\n`~!@#$%^&*()-_—+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。， 、？]";
        String regExless = "[\\s+\r\n。.?？]";
        String[] s = poemBasic.getPoem().getPoem_text().split(regExless);
        List<String> newstrings = new ArrayList<>();
        for (int j = 0; j < s.length; j++) {
            if (!s[j].isEmpty()) {
                newstrings.add(s[j]);
            }
        }
        poemBasic.getPoem().setPoem_textlines(newstrings);

        return poemBasic;

    }

    public static List<Poem> setText(List<Poem> poemList){
        String regEx = "[\\s+\r\n`~!@#$%^&*()-_—+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。， 、？]";
        for (Poem poem : poemList
        ) {
            String[] s = poem.getPoem_text().split(regEx);
            List<String> newstrings = new ArrayList<>();
            for (int j = 0; j < s.length; j++) {
                if (!s[j].isEmpty()) {
                    newstrings.add(s[j]);
                }
            }
            poem.setPoem_textlines(newstrings);
        }
        return poemList;
    }
}
